package com.hxy.subject.application.controller;

import com.alibaba.fastjson.JSON;
import com.hxy.subject.application.convert.SubjectCategoryDTOConverter;
import com.hxy.subject.application.convert.SubjectInfoDTOConverter;
import com.hxy.subject.application.dto.AddSubjectCategoryDTO;
import com.hxy.subject.application.dto.DelSubjectCategoryDTO;
import com.hxy.subject.application.dto.EditSubjectCategoryDTO;
import com.hxy.subject.application.dto.SubjectInfoDTO;
import com.hxy.subject.common.entity.Result;
import com.hxy.subject.common.entity.RowsData;
import com.hxy.subject.domain.entity.SubjectCategoryBO;
import com.hxy.subject.domain.entity.SubjectInfoBO;
import com.hxy.subject.domain.service.SubjectInfoDomainService;
import com.hxy.subject.infra.basic.entity.SubjectInfo;
import com.hxy.subject.infra.basic.service.SubjectCategoryService;
import com.hxy.subject.infra.basic.service.SubjectInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * 刷题controller
 *
 * @Author haoxuyang
 * @Date 2024/9/2 17:15
 */
@Slf4j
@RestController
@RequestMapping("/subject/info")
public class SubjectController {

    @Resource
    private SubjectInfoDomainService subjectInfoDomainService;

    @PostMapping("/add")
    public Result<String> add(@RequestBody @Validated SubjectInfoDTO dto) {
        log.info("dto:" + JSON.toJSONString(dto));
        SubjectInfoBO subjectInfoBO = SubjectInfoDTOConverter.INSTANCE.subjectCategoryDtoToBo(dto);
        subjectInfoDomainService.add(subjectInfoBO);
        return Result.success("操作成功");
    }

    @PostMapping("/update")
    public Result<String> update(@RequestBody @Validated SubjectInfoDTO dto) {
        SubjectInfoBO SubjectInfoDTO = SubjectInfoDTOConverter.INSTANCE.subjectCategoryDtoToBo(dto);
       // subjectInfoDomainService.update(SubjectInfoDTO);
        return Result.success("操作成功");
    }

    @PostMapping("/delete")
    public Result<String> delete(@RequestBody @Validated SubjectInfoDTO dto) {
        SubjectInfoBO SubjectInfoDTO = SubjectInfoDTOConverter.INSTANCE.subjectCategoryDtoToBo(dto);
        //subjectInfoDomainService.delete(SubjectInfoDTO);
        return Result.success("操作成功");
    }

    @PostMapping("/list")
    public Result<RowsData<SubjectInfoDTO>> list(@RequestBody @Validated SubjectInfoDTO dto) {
        SubjectInfoBO SubjectInfoDTO = SubjectInfoDTOConverter.INSTANCE.subjectCategoryDtoToBo(dto);
        //subjectInfoDomainService.delete(SubjectInfoDTO);
        return Result.success("操作成功");
    }


}
